package com.clz.appdesign.appdependence.base.mvp;

import android.os.Bundle;
import android.support.annotation.Nullable;

import com.clz.appdesign.appdependence.base.BaseFragment;


/**
 * @author chenliangzhi
 * @date 2018/3/19
 * @describe
 */

public abstract class MvpFragment<V, P extends BasePresenter<V>> extends BaseFragment implements BaseView {
    protected P mPresenter;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void beforeInit() {
        super.beforeInit();
        mPresenter = initPresenter();
        mPresenter.attach((V) this);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
    }

    @Override
    public void onDestroyView() {
        mPresenter.detach();
        super.onDestroyView();
    }

    /**
     * 初始化presenter
     *
     * @return
     */
    public abstract P initPresenter();

    @Override
    public void showLoading() {
        show2Loading();
    }

    @Override
    public void hideLoading() {
        hide2Loading();
    }
}
